﻿namespace EyeOpen.Data.Nibernate.Mapping
{
    using EyeOpen.Domain;
    using FluentNHibernate.Mapping;
    
    public abstract class UniqueEntityMap<T> : ClassMap<T> where T : UniqueEntity
    {
        /// <summary>
        /// Represents the unique relation attribute.
        /// </summary>
        protected const string UniqueKeyAttribute = "unique-key";

        protected UniqueEntityMap() 
        {
            Id(x => x.Id)
                .GeneratedBy
                .Assigned();

            WithTable(MappedTableName);
        }

        protected virtual string MappedTableName
        {
            get
            {
                var tableName = GetType().BaseType.GetGenericArguments()[0].Name;
                tableName = string.Format("[{0}]", tableName);

                return tableName;
            }
        }
    }
}